import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const baseUrl = CommonConfig.bmsUrl + '/v1'

/**
 * 获取设备列表，通过设备名称
 * deviceName 设备名称
 * tenantId 企业id
 * **/
export function getDevicesByName (params) {
  const newUrl = baseUrl + '/listDevice_By_DeviceName'

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 获取设备列表，通过盒子id
 * boxId 盒子id
 * tenantId 企业id
 * **/
export function getDevicesByBoxid (params) {
  const newUrl = baseUrl + '/listDevice_By_BoxId'

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 增加盒子
 * boxId 盒子id
 * boxModel 盒子型号
 * customerManagers 客户经理
 * deployedDate 部署日期
 * factoryBroker 工厂对接人
 * tenantId 企业id
 * **/
export function addBox (params) {
  const newUrl = baseUrl + `/box`

  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 绑定盒子
 * boxId 盒子id
 * deviceId 设备id
 * **/
export function boxBind (params) {
  const newUrl = baseUrl + `/box_binding`

  return axiosInstance.patch(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 解绑盒子
 * deviceId 设备id
 * boxId 盒子解绑
 * **/
export function boxUnBind (params) {
  const newUrl = baseUrl + `/box_unBinding`

  return axiosInstance.patch(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 获取企业列表不分页
 * deviceId 设备id
 * **/
export function getCompany (params) {
  const newUrl = baseUrl + `/companies_no_page`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}
